﻿using UnityEngine;

namespace GameToolkit.BehaviourTree
{
    [DisallowMultipleComponent]
    public class BehaviourTreeRunner : BehaviourTreeExecutableMono, ICullingUpdate, ICullingComponent
    {
        [SerializeField]
        ECullDistance m_VisibleDistance = ECullDistance.Far;

        [SerializeField]
        ECullDistance m_InvisibleDistance = ECullDistance.NearBy;

        [SerializeField]
        ECullingUpdateMode m_UpdateMode = ECullingUpdateMode.Update;

        int ICullingUpdate.CulledUpdateDistanceLv => (int)m_VisibleDistance;

        int ICullingUpdate.AlwaysUpdateDistanceLv => (int)m_InvisibleDistance;

        ECullingUpdateMode ICullingUpdate.UpdateMode => m_UpdateMode;

        void ICullingComponent.OnCullingDisabled()
        {
            StopBehaviour();
        }

        void ICullingComponent.OnCullingEnabled(CullingCamera culler, ICullingBounds target)
        {
            StartBehaviour();
        }

        void ICullingUpdate.OnCullingUpdate(CullingCamera culler, ECullingUpdateMode mode)
        {
            UpdateBehaviour(culler.deltaTime, mode);
        }
    }
}
